<template>
	<view class="container">
		<!-- 分类导航 -->
		<view class="card mb-20">
			<scroll-view scroll-x class="scroll-x">
				<view class="flex">
					<view class="category-item" :class="{active: activeCategory === index}" v-for="(item, index) in categoryList" :key="index" @click="switchCategory(index)">
						{{ item }}
					</view>
				</view>
			</scroll-view>
		</view>
		
		<!-- 资讯列表 -->
		<view class="info-list">
			<view class="card mb-20" v-for="(item, index) in infoList" :key="index" @click="goToDetail(item)">
				<view v-if="item.type === 'image'">
					<image :src="item.image" mode="widthFix" style="width: 100%; border-radius: 10rpx;"></image>
					<text class="block mt-20" style="font-weight: bold; font-size: 32rpx;">{{ item.title }}</text>
				</view>
				<view v-else class="flex">
					<view style="flex: 1;">
						<text class="block" style="font-weight: bold; font-size: 32rpx;">{{ item.title }}</text>
						<text class="block text-gray mt-10">{{ item.desc }}</text>
					</view>
					<image :src="item.image" mode="aspectFill" style="width: 200rpx; height: 150rpx; border-radius: 10rpx; margin-left: 20rpx;"></image>
				</view>
				<view class="flex justify-between mt-20">
					<view class="flex">
						<text class="text-gray">{{ item.author }}</text>
						<text class="text-gray ml-20">{{ item.time }}</text>
					</view>
					<view class="flex">
						<text class="iconfont icon-eye text-gray" style="margin-right: 10rpx;"></text>
						<text class="text-gray">{{ item.view }}</text>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				activeCategory: 0,
				categoryList: ['推荐', '攻略', '美食', '住宿', '交通', '购物', '娱乐'],
				infoList: [
					{
						id: 1,
						title: '北京夏日避暑好去处，这些地方你去过几个？',
						type: 'image',
						image: '/static/info1.jpg',
						author: '旅游达人',
						time: '2023-06-10',
						view: 1280
					},
					{
						id: 2,
						title: '北京特色小吃推荐，吃货必看攻略',
						desc: '北京作为历史悠久的古都，不仅有丰富的文化古迹，还有众多特色小吃...',
						type: 'text',
						image: '/static/info2.jpg',
						author: '美食博主',
						time: '2023-06-08',
						view: 960
					},
					{
						id: 3,
						title: '北京五日游详细攻略，让你玩得尽兴不踩雷',
						desc: '第一次来北京旅游？这份超详细攻略你一定要收藏...',
						type: 'text',
						image: '/static/info3.jpg',
						author: '旅行攻略',
						time: '2023-06-05',
						view: 2100
					}
				]
			}
		},
		methods: {
			switchCategory(index) {
				this.activeCategory = index;
			},
			goToDetail(item) {
				uni.navigateTo({
					url: '/pages/info/detail?id=' + item.id
				})
			}
		}
	}
</script>

<style>
	.scroll-x {
		white-space: nowrap;
		width: 100%;
	}
	
	.category-item {
		display: inline-block;
		padding: 15rpx 30rpx;
		margin-right: 20rpx;
		border-radius: 30rpx;
		background: #f5f5f5;
	}
	
	.category-item.active {
		background: #4caf50;
		color: #fff;
	}
</style>